package xyz.labmem.app.main

import javafx.beans.property.SimpleObjectProperty
import javafx.scene.layout.HBox
import javafx.scene.layout.Pane
import xyz.labmem.app.unit.*
import xyz.labmem.lipx.core.Type


class CenterPane(val stage: MainStage) : HBox() {
    private var center = SimpleObjectProperty(Pane())
    private var proxyListUnit: ProxyListUnit
    private var homePageUnit: HomePageUnit
    private var serverUnit: ServerUnit
    private var settingUnit: SettingUnit

    init {
        style = """
            -fx-background-color: #070709;
            -fx-background-image: url("image/ui/bg.png");  
            -fx-background-size: 162px; 
            -fx-background-repeat: repeat;  
            -fx-background-position: center; 
        """.trimIndent()
        prefHeightProperty().bind(stage.root.prefHeightProperty().subtract(stage.td.heightProperty()).subtract(20))
        prefWidthProperty().bind(stage.root.prefWidthProperty().subtract(20))
        layoutY = 10.0
        layoutX = 10.0
        children.add(MenuUnit(this))
        children.add(center.value)
        proxyListUnit = ProxyListUnit(this)
        serverUnit = ServerUnit(this)
        homePageUnit = HomePageUnit(this)
        settingUnit = SettingUnit(this)
        center.addListener { _, old, new ->
            children.remove(old)
            children.add(new)
        }
    }

    fun showProxyUnit(btn: MenuBtn, type: Type) {
        center.value = proxyListUnit
        proxyListUnit.groupList.showList(btn.layoutY + 20, type)
    }

    fun showHomePage() {
        center.value = homePageUnit
    }

    fun showServerPage() {
        center.value = serverUnit
        serverUnit.refresh()
    }

    fun showSettingPage() {
        center.value = settingUnit
    }



}